const path = require('path');
const webpack = require('webpack');

module.exports = {
    entry: './src/App.tsx',
    watch: true,
    output: {
        path: path.join(__dirname, 'build'),
        filename: "bundle.js",
    },
    cache: true,
    // devServer: {
    //     proxy: {
    //         '/api': {
    //             target: 'http://192.168.88.176:8080/ad-admin',
    //             // target: 'http://192.168.95.111:8080/xiaopai-flj',
    //             secure: false,
    //             changeOrigin: true
    //         }
    //     },
    // },
    resolve: {
        // modules: [
        //     path.join(__dirname, "src"),
        //     "node_modules"
        // ],
        // alias: {
        //     'react': 'react/dist/react.min.js',
        //     'react-dom': 'react-dom/dist/react-dom.min.js',
        //     'antd': 'antd/dist/antd.min.js',
        // },
        // alias: {
        //     'react': 'react-lite',
        //     'react-dom': 'react-lite'
        // },
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
    },
    devtool: 'cheap-module-eval-source-map',
    module: {
        rules: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
            {
                test: /\.(css|less)$/,
                include: [
                    /src/,
                    '/node_modules/antd/' //增加此项
                ],
                use: ['style-loader', {loader: 'css-loader', options: {importLoaders: 1}}, 'less-loader']
            },
            // {
            //     test: /\.tsx?$/,
            //     loader: "babel-loader!awesome-typescript-loader",
            //     exclude: /node_modules/
            // },
            {
                test: /\.tsx?$/,
                loader: "awesome-typescript-loader",
                exclude: /node_modules/
            },
            // {
            //     'loader': 'babel-loader',
            //     'test': /\.js$/,
            //     'exclude': /node_modules/,
            //     'query': {
            //         'plugins': ['lodash']
            //     }
            // }
        ],
        noParse: /moment/,
    },

    externals: {
        lodash: '_',
        'lodash/fp': '_',
        mobx: 'mobx',
        'mobx-react': 'mobxReact',
        axios: 'axios',
        moment: 'moment',
        react: 'React',
        'react-dom': 'ReactDOM',
        'antd': 'antd'
    },

    plugins: [
        // 'lodash',
        new webpack.optimize.ModuleConcatenationPlugin(),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),

        // new webpack.optimize.UglifyJsPlugin({
        //     compress: {
        //         warnings: false
        //     },
        //     except: ['$super', '$', 'exports', 'require']
        // })
    ]

};